﻿/*
(c) 2010 - Open Source Business Foundation e. V. (www.osbf.de)
This software is provided under Microsoft Reciprocal License (Ms-RL)
(http://www.microsoft.com/opensource/licenses.mspx#Ms-RL)
All other rights reserved
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MicroFormatProcessing {
    /// <summary>
    /// This class is doing the appending and splitting of the property names and values of a Microformat
    /// </summary>
    
    public static class SerializeUtil
    {
        public const string DELIMITER = "@@";

        public static string SerializeArray(string[] stringArray)
        {
            if ((stringArray != null) && (stringArray.Length > 0))
            {
                StringBuilder serialized = new StringBuilder();
                for (int i = 0; i < stringArray.Length; i++)
                {
                    if (i > 0)
                    {
                        serialized.Append(DELIMITER);
                    }
                    serialized.Append(stringArray[i]);
                }
                return serialized.ToString();
            }
            else
            {
                return null;
            }
        }

        public static string[] DeSerializeString(string serializedString)
        {
            if ((serializedString != null) && (serializedString.Length > 0))
            {
                return Regex.Split(serializedString, DELIMITER);
            }
            else
            {
                return new string[0];
            }
        }
    }
}